package com.flydog.taskManager.common.vaildator;

import com.flydog.taskManager.dto.PhasedTaskParam;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 阶段性工作实现类
 *
 * @author caoweidong
 * @version 0.0.0
 * @create 2021/6/30 15:44
 */
public class PhaseTaskValidatorClass implements ConstraintValidator<PhaseTaskValidator, PhasedTaskParam> {
    @Override
    public void initialize(PhaseTaskValidator constraintAnnotation) {

    }

    @Override
    public boolean isValid(PhasedTaskParam phasedTaskParam, ConstraintValidatorContext constraintValidatorContext) {
        if (phasedTaskParam.getEnd().before(phasedTaskParam.getBegin())) {
            constraintValidatorContext
                    .buildConstraintViolationWithTemplate("结束时间不能在开始时间之前")
                    .addPropertyNode("end")
                    .addConstraintViolation()
                    .buildConstraintViolationWithTemplate("结束时间不能在开始时间之前")
                    .addPropertyNode("begin")
                    .addConstraintViolation();;
            return false;
        }
        return true;
    }
}
